<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<meta name="csrf-token" content="{{ csrf_token() }}">
		<title>盈亏状态</title>
		<link rel="stylesheet" type="text/css" href="css/base.css" />
		{{--<link rel="stylesheet" type="text/css" href="css/mui.min.css" />--}}
		<link rel="stylesheet" type="text/css" href="css/public.css"/>
		<link rel="stylesheet" type="text/css" href="css/profit-loss.css" />
		<script src="js/flexible.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/mui.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/gVerify.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/jquery-3.1.1.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<style>
		.start{
			display: inline-block;
			padding: .3em .5em;
			background-image: linear-gradient(#ddd, #bbb);
			border: 1px solid rgba(0,0,0,.2);
			border-radius: .3em;
			box-shadow: 0 1px white inset;
			text-align: center;
			text-shadow: 0 1px 1px black;
			color:white;
			font-weight: bold;
		}
		.end{
			display: inline-block;
			padding: .3em .5em;
			background-image: linear-gradient(#ddd, #bbb);
			border: 1px solid rgba(0,0,0,.2);
			border-radius: .3em;
			box-shadow: 0 1px white inset;
			text-align: center;
			text-shadow: 0 1px 1px black;
			color:red;
			font-weight: bold;
		}
	</style>
	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" style="color: #000;"></a>
			<h1 class="mui-title">盈亏状态</h1>
		</header>
		<div class="content">
			<h4>选择交易所</h4>
			<select name="ex_id" id="ex">
				@foreach($list as $v)
					<option value="{{ $v->ex_id }}">{{ $v->name }}</option>
				@endforeach
			</select>
			<h4>选择账号</h4>
			<select name="username" id="username">
				<option value="">账号1</option>
				<option value="">账号2</option>
			</select>
			 <table border="" cellspacing="" cellpadding="" id="table">
			 	<tr>
			 		<th>币种名称</th>
			 		<th>折合USDT</th>
			 		<th>折合人民币</th>
			 		<th>盈亏率</th>
			 		<th>状态</th>
			 	</tr>
			 </table>
		</div>
		<script type="text/javascript">
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
			$('.exchange li').on("tap",function(){
				var _index=$(this).index();
				$(this).addClass('exchangeChecked').siblings().removeClass("exchangeChecked");
			});
			var ex=$('#ex').val();
			$.ajaxSettings.async=false;
			$.post('selUsername',{ex_id:ex},function(e){
			    var html='';
			    $.each(e.data,function(k,v){
			        html+='<option value="'+v.id+'">'+v.username+'</option>';
				});
				$('#username').html(html);

			});
			$('#ex').change(function(){
                $.post('selUsername',{ex_id:ex},function(e){
                    var html='';
                    $.each(e.data,function(k,v){
                        html+='<option value="'+v.id+'">'+v.username+'</option>';
                    });
                    $('#username').html(html);
                });
			});
			var username=$('#username').val();
			$.post('currBalance',{account_id:username,ex_id:ex},function(e){
				var html='';
				$.each(e.data,function(k,v){
				    html+='<tr>\n' +
                        '\t\t\t \t    <td>'+v.coin_name+'</td>\n' +
                        '\t\t\t \t    <td>'+v.am_usdt+'$</td>\n' +
                        '\t\t\t \t    <td>'+v.am_usdt*7+'￥</td>\n' +
                        '\t\t\t \t    <td>'+v.profit_rate+'%</td>\n' +
                        '\t\t\t \t    <td>';
				    if(v.op_status==0){
                        html+='<button class="start">开始</button><button class="end">停止</button>';
					}else{
                        html+='<button class="start">工作中</button><button class="end">停止</button>';
					}
					html+='</td> </tr>';
				});
				$('#table').append(html);
			});
			//开始
			$('#table').on('click','.start',function(){
			    var curr=$(this).parent().prevAll().eq(3).text();
                $.post('bus',{ex_id:ex,curr:curr,status:1,account:username},function(e){
					alert(e.msg);
				})
			});
			//结束
            $('.end').click(function(){
                var curr=$(this).parent().prevAll().eq(3).text();
                $.post('bus',{ex_id:ex,curr:curr,status:0,account:username},function(e){
                    alert(e.msg)
                })
            })
		</script>
	</body>
</html>